# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： random
Description :
Author : 'li'
date： 2022/1/19
-------------------------------------------------
Change Activity:
2022/1/19:
-------------------------------------------------
"""
import random
import uuid

import numpy as np


def get_uuid_str():
    """
    get random uuid string.

    Returns: uuid string.

    """
    return str(uuid.uuid4()).replace('-', '')


def random_ture_or_false(true_ratio=0.9):
    """
    return true or false according to ratio.

    Args:
        true_ratio: the ratio of return true

    Returns:

    """
    if random.random() < true_ratio:
        return True
    return False


def random_fetch_item_from_list(list_info, size):
    """
    Random fetch items from list.
    Args:
        list_info:
        size:

    Returns:

    """
    return np.random.choice(list_info, size).tolist()


def fetch_element_by_probability(elements_lst, probability_lst):
    """

    Args:
        elements_lst:
        probability_lst:

    Returns:

    """
    assert len(elements_lst) == len(probability_lst)
    assert np.array(probability_lst).sum() == 1
    x = random.uniform(0, 1)
    cumulative_probability = 0.0
    for item, item_probability in zip(elements_lst, probability_lst):
        cumulative_probability += item_probability
        if x <= cumulative_probability:
            return item
    raise Exception('fate error.')


def get_random_int(start, end):
    """
    get a random int ,start<=v<end.
    Args:
        start:
        end:

    Returns:

    """
    return random.randrange(start, end)
